<?php

namespace IDock\Insurance\ZSIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\ZSIC\Response\AllZSICResponse;
use IDock\Insurance\ZSIC\ZSICEnums;
use IDock\Printer\NonCar\NonCarInquirySinglePrinter;
use IDock\Printer\NonCar\NonCarUnderwritingPrinter;
use IDock\Printer\Premium\PremiumBIPrinter;
use IDock\Printer\Premium\PremiumCIPrinter;
use IDock\Printer\Premium\PremiumCoveragePrinter;
use IDock\Printer\Premium\PremiumFactorPrinter;
use IDock\Printer\Premium\PremiumInquiryPrinter;
use IDock\Printer\Premium\PremiumTaxPrinter;
use IDock\Printer\PremiumUnderwritingPrinter;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;
use IDock\Visitor\NonCar\NonCarProductVisitor;

class UnderwritingResponse extends AllZSICResponse
{
    /*** @var PremiumUnderwritingPrinter $printer */
    public $printer = PremiumUnderwritingPrinter::class;

    public function printerInit() :Response
    {
        $premiumInquiryPrinter = new PremiumInquiryPrinter();
        $body = $this->getBody()['body'] ?? '';
        $data = $body['base'] ?? [];
        $code = $data['uwFlag'] ?? '';

        $this->printer->inquiryNo = $data['orderNo'] ?? '';
        $this->printer->ciInquiryNo = $data['tciProposalNo'] ?? '';
        $this->printer->biInquiryNo = $data['vciProposalNo'] ?? '';
        $this->printer->argc['tciProposalNo'] = $data['tciProposalNo'] ?? '';
        $this->printer->argc['vciProposalNo'] = $data['vciProposalNo'] ?? '';
        $this->printer->argc['orderNo'] = $data['orderNo'] ?? '';
        $this->printer->messageTip = $data['uwMsg'] ?? '';
        $this->printer->argc['nonCarProposalNo'] = $body['nonVehicleProducts']['nonVehicleProduct']['proposalNo'] ?? '';
        //非车
        if ($body['nonVehicleProducts'] ?? '') {
            $nonCarInquiryPrinter = new NonCarUnderwritingPrinter();
            /*** @var $item NonCarProductVisitor */
            $single = new NonCarInquirySinglePrinter();
            $single->inquiryNo =  $body['nonVehicleProducts']['nonVehicleProduct']['proposalNo'] ?? '';
            $single->planCode = $body['nonVehicleProducts']['nonVehicleProduct']['planCode'] ?? '';
            $single->productCode = $body['nonVehicleProducts']['nonVehicleProduct']['productCode'] ?? '';
            $single->statusCode = 'success';
            $nonCarInquiryPrinter->nonCarSingleAppend($single);
            $this->printer->noCarUnderwritingPrinter = $nonCarInquiryPrinter;
        }

        //下发
        if ($code == '2') {
            $this->printer->statusCode = 'U4';
        }
        //成功
        if ($code == '1' or $code == '3')  {
            $this->printer->statusCode = 'U1';
        }
        //人工
        if ($code == '9') {
            $this->printer->statusCode = 'U3';
        }
        //拒保
        if ($code == '4') {
            $this->printer->statusCode = 'U6';
        }

        return $this;
    }


}
